package org.example.service;

import org.example.entity.JobPost;
import org.example.enums.JobPostStatus;
import org.example.repository.JobPostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JobPostService {

    private final JobPostRepository jobPostRepository;

    @Autowired
    public JobPostService(JobPostRepository jobPostRepository) {
        this.jobPostRepository = jobPostRepository;
    }

    public List<JobPost> findAllJobs() {
        return jobPostRepository.findAll();
    }

    public void updateJobPostStatus(Long id, String status) {
        JobPost jobPost = jobPostRepository.findById(id)
                .orElseThrow(() -> new RuntimeException("JobPost not found"));
        jobPost.setStatus(JobPostStatus.fromString(status));
        jobPostRepository.save(jobPost);
    }

    public void deleteJobPost(Long id) {
        jobPostRepository.deleteById(id);
    }
}
